﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//public partial class Theme_index_OpenNews :PowerCreator.LMS.Web.Base.WebBasePage    by windbell↓
public partial class Theme_Index_jyzx : System.Web.UI.Page
{
    PowerCreator.LMS.Web.CMS.NewType opNewsType = new PowerCreator.LMS.Web.CMS.NewType();
    PowerCreator.LMS.Web.CMS.New opNews = new PowerCreator.LMS.Web.CMS.New();
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    private int iPageSize = 15;

    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            string str_newstype = Request.QueryString["newstype"].ToString();
            ViewState["newstype"] = str_newstype;

            string str_newstypename = Request.QueryString["newstypename"].ToString();
            ViewState["newstypename"] = str_newstypename;

            this.Title = str_newstypename;
            lbl_NewsTypeName.Text = str_newstypename;
            BinderPager();
            BinderNews_GZ(str_newstype, 1);
            
        }
    }

    private void BinderNews_GZ(string str_newtypeid,int pageindex)
    {
        string search = string.Format(" FKNewNewTypeID={0} and NewState=1", str_newtypeid);
        string orderby = "NewIsTop desc, NewPublishTime desc ";
        DataTable dt1 = opNews.Query(search, orderby, iPageSize, pageindex);
        for (int j = 0; j < dt1.Rows.Count; j++)
        {
            if (dt1.Rows[j]["NewUrl"] == null)
                dt1.Rows[j]["NewUrl"] = "OpenNews.aspx?NewsID=" + dt1.Rows[j]["NewID"].ToString();
            else if (dt1.Rows[j]["NewUrl"].ToString().Length == 0)
                dt1.Rows[j]["NewUrl"] = "OpenNews.aspx?NewsID=" + dt1.Rows[j]["NewID"].ToString();

            dt1.Rows[j]["NewPublishTime"] = DateTime.Parse(dt1.Rows[j]["NewPublishTime"].ToString()).ToString("MM-dd");
        }
        rpt_news_gn.DataSource = dt1;
        rpt_news_gn.DataBind();
        //PreAspNetPager(AspNetPager1); by windbell2，由于把page继承于PowerCreator.LMS.Web.Base.WebBasePage 改成了System.Web.UI.Page ，该方法失效
    }

    private void BinderPager()
    {
        string search = string.Format(" FKNewNewTypeID={0}", ViewState["newstype"].ToString().Trim());
        AspNetPager1.PageSize = iPageSize;
        AspNetPager1.RecordCount = opNews.Count(search);
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BinderNews_GZ(ViewState["newstype"].ToString().Trim(), AspNetPager1.CurrentPageIndex);
    } 
}
